home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / guile-ii.src / guile-ii / guile-src / libguile / gc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-17  |  9.4 KB  |  310 lines

  1. /* classes: h_files */
  2.  
  3. #ifndef GCH
  4. #define GCH
  5. /*    Copyright (C) 1995 Free Software Foundation, Inc.
  6.  * 
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 2, or (at your option)
  10.  * any later version.
  11.  * 
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this software; see the file COPYING.  If not, write to
  19.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  *
  21.  * As a special exception, the Free Software Foundation gives permission
  22.  * for additional uses of the text contained in its release of GUILE.
  23.  *
  24.  * The exception is that, if you link the GUILE library with other files
  25.  * to produce an executable, this does not by itself cause the
  26.  * resulting executable to be covered by the GNU General Public License.
  27.  * Your use of that executable is in no way restricted on account of
  28.  * linking the GUILE library code into it.
  29.  *
  30.  * This exception does not however invalidate any other reasons why
  31.  * the executable file might be covered by the GNU General Public License.
  32.  *
  33.  * This exception applies only to the code released by the
  34.  * Free Software Foundation under the name GUILE.  If you copy
  35.  * code from other Free Software Foundation releases into a copy of
  36.  * GUILE, as the General Public License permits, the exception does
  37.  * not apply to the code that you add in this way.  To avoid misleading
  38.  * anyone as to the status of such modified files, you must delete
  39.  * this exception notice from them.
  40.  *
  41.  * If you write modifications of your own for GUILE, it is your choice
  42.  * whether to permit this exception to apply to your modifications.
  43.  * If you do not wish that, delete this exception notice.  
  44.  */
  45.  
  46.  
  47. #include "__scm.h"
  48.  
  49.  
  50. #ifdef vms
  51. # ifndef CHEAP_CONTINUATIONS
  52.  
  53.    typedef int jmp_buf[17];
  54.    extern int setjump(jmp_buf env);
  55.    extern int longjump(jmp_buf env, int ret);
  56.  
  57. #  define setjmp setjump
  58. #  define longjmp longjump
  59. # else
  60. #  include <setjmp.h>
  61. # endif
  62. #else                /* ndef vms */
  63. # ifdef _CRAY1
  64.     typedef int jmp_buf[112];
  65.     extern int setjump(jmp_buf env);
  66.     extern int longjump(jmp_buf env, int ret);
  67.  
  68. #  define setjmp setjump
  69. #  define longjmp longjump
  70. # else                /* ndef _CRAY1 */
  71. #  include <setjmp.h>
  72. # endif                /* ndef _CRAY1 */
  73. #endif                /* ndef vms */
  74.  
  75.  
  76. /* James Clark came up with this neat one instruction fix for
  77.    continuations on the SPARC.  It flushes the register windows so
  78.    that all the state of the process is contained in the stack. */
  79.  
  80. #ifdef sparc
  81. # define FLUSH_REGISTER_WINDOWS asm("ta 3")
  82. #else
  83. # define FLUSH_REGISTER_WINDOWS /* empty */
  84. #endif
  85.  
  86. /* If stack is not longword aligned then */
  87.  
  88. /* #define SHORT_ALIGN */
  89. #ifdef THINK_C
  90. # define SHORT_ALIGN
  91. #endif
  92. #ifdef MSDOS
  93. # define SHORT_ALIGN
  94. #endif
  95. #ifdef atarist
  96. # define SHORT_ALIGN
  97. #endif
  98.  
  99. /* If stacks grow up then */
  100.  
  101. /* #define STACK_GROWS_UP */
  102. #ifdef hp9000s800
  103. # define STACK_GROWS_UP
  104. #endif
  105. #ifdef pyr
  106. # define STACK_GROWS_UP
  107. #endif
  108. #ifdef nosve
  109. # define STACK_GROWS_UP
  110. #endif
  111. #ifdef _UNICOS
  112. # define STACK_GROWS_UP
  113. #endif
  114.  
  115. /* CELL_UP and CELL_DN are used by scm_init_heap_seg to find scm_cell aligned inner
  116.    bounds for allocated storage */
  117.  
  118. #ifdef PROT386
  119. /*in 386 protected mode we must only adjust the offset */
  120. # define CELL_UP(p) MK_FP(FP_SEG(p), ~7&(FP_OFF(p)+7))
  121. # define CELL_DN(p) MK_FP(FP_SEG(p), ~7&FP_OFF(p))
  122. #else
  123. # ifdef _UNICOS
  124. #  define CELL_UP(p) (CELLPTR)(~1L & ((long)(p)+1L))
  125. #  define CELL_DN(p) (CELLPTR)(~1L & (long)(p))
  126. # else
  127. #  define CELL_UP(p) (CELLPTR)(~(sizeof(scm_cell)-1L) & ((long)(p)+sizeof(scm_cell)-1L))
  128. #  define CELL_DN(p) (CELLPTR)(~(sizeof(scm_cell)-1L) & (long)(p))
  129. # endif                /* UNICOS */
  130. #endif                /* PROT386 */
  131.  
  132.  
  133. /* {heap parameters}
  134.  * 
  135.  * These are parameters for controlling memory allocation.  The heap
  136.  * is the area out of which scm_cons, object headers, and large objects
  137.  * are allocated.
  138.  *
  139.  * The heap consists of a number of segments.  Each segment 
  140.  * contains objects of only one size, specified when the segment is
  141.  * created.
  142.  *
  143.  * Each heap cell is 8 bytes on a 32 bit machine and 16 bytes on a
  144.  * 64 bit machine.  The units of the _SIZE parameters are bytes.
  145.  * Cons pairs and object headers occupy one heap cell.
  146.  * Large objects may occupy any number of cells.
  147.  *
  148.  * INIT_HEAP_SIZE is the initial size of heap.  If this much heap is
  149.  * allocated initially the heap will grow by half its current size
  150.  * each subsequent time more heap is needed.
  151.  *
  152.  * If INIT_HEAP_SIZE heap cannot be allocated initially, HEAP_SEG_SIZE
  153.  * will be used, and the heap will grow by HEAP_SEG_SIZE when more
  154.  * heap is needed.  HEAP_SEG_SIZE must fit into type sizet.  This code
  155.  * is in scm_init_storage() and alloc_some_heap() in sys.c
  156.  * 
  157.  * If INIT_HEAP_SIZE can be allocated initially, the heap will grow by
  158.  * EXPHEAP(scm_heap_size) when more heap is needed.
  159.  *
  160.  * MIN_HEAP_SEG_SIZE is minimum size of heap to accept when more heap
  161.  * is needed.
  162.  *
  163.  * INIT_MALLOC_LIMIT is the initial amount of malloc usage which will
  164.  * trigger a GC. 
  165.  */
  166.  
  167. #define INIT_HEAP_SIZE (25000L*sizeof(scm_cell))
  168. #define MIN_HEAP_SEG_SIZE (2000L*sizeof(scm_cell))
  169. #ifdef _QC
  170. # define HEAP_SEG_SIZE 32400L
  171. #else
  172. # ifdef sequent
  173. #  define HEAP_SEG_SIZE (7000L*sizeof(scm_cell))
  174. # else
  175. #  define HEAP_SEG_SIZE (8100L*sizeof(scm_cell))
  176. # endif
  177. #endif
  178. #define EXPHEAP(scm_heap_size) (scm_heap_size*2)
  179. #define INIT_MALLOC_LIMIT 100000
  180.  
  181. #ifdef SHORT_ALIGN
  182. typedef short SCM_STACKITEM;
  183. #else
  184. typedef long SCM_STACKITEM;
  185. #endif
  186. typedef struct 
  187. {
  188.   jmp_buf jmpbuf;
  189.   SCM dynenv;
  190.   SCM_STACKITEM *base;
  191.   unsigned long seq;
  192. } regs;
  193. #define JMPBUF(x) (((regs *)CHARS(x))->jmpbuf)
  194. #define SETJMPBUF SETCDR
  195. #define DYNENV(x) (((regs *)CHARS(x))->dynenv)
  196. #define BASE(x) (((regs *)CHARS(x))->base)
  197. #define SEQ(x) (((regs *)CHARS(x))->seq)
  198.  
  199. #define SCM_PTR_GT(x, y) PTR_LT(y, x)
  200. #define SCM_PTR_LE(x, y) (!PTR_GT(x, y))
  201. #define SCM_PTR_GE(x, y) (!PTR_LT(x, y))
  202.  
  203. struct scm_heap_seg_data
  204. {
  205.   SCM_CELLPTR bounds[2];    /* lower and upper */
  206.   SCM *freelistp;        /* the value of this may be shared */
  207.   int ncells;            /* per object in this segment */
  208.   int (*valid) P ((SCM_CELLPTR, struct scm_heap_seg_data *));
  209. };
  210.  
  211. extern struct scm_heap_seg_data *scm_heap_table;
  212. extern int scm_n_heap_segs;
  213. extern int scm_take_stdin;
  214.  
  215. extern SCM scm_sys_protects[];
  216. extern sizet scm_num_protects;
  217.  
  218.  
  219.  
  220. #define scm_cur_inp scm_sys_protects[0]
  221. #define scm_cur_outp scm_sys_protects[1]
  222. #define scm_cur_errp scm_sys_protects[2]
  223. #define scm_def_inp scm_sys_protects[3]
  224. #define scm_def_outp scm_sys_protects[4]
  225. #define scm_def_errp scm_sys_protects[5]
  226. #define scm_listofnull scm_sys_protects[6]
  227. #define scm_undefineds scm_sys_protects[7]
  228. #define scm_nullvect scm_sys_protects[8]
  229. #define scm_nullstr scm_sys_protects[9]
  230. #define scm_symhash scm_sys_protects[10]
  231. #define scm_progargs scm_sys_protects[11]
  232. #define scm_transcript scm_sys_protects[12]
  233. #define scm_rootcont scm_sys_protects[13]
  234. #define scm_dynwinds scm_sys_protects[14]
  235. #define scm_symhash_vars scm_sys_protects[15]
  236. #define scm_permobjs scm_sys_protects[16]
  237. #define scm_flo0 scm_sys_protects[17]
  238. #define scm_kw_obarray scm_sys_protects[18]
  239. #define scm_type_obj_list scm_sys_protects[19]
  240. #define scm_first_type scm_sys_protects[20]
  241. #define scm_stand_in_procs scm_sys_protects[21]
  242. #define SCM_NUM_PROTECTS 22
  243.  
  244.  
  245.  
  246.  
  247. extern long scm_heap_size;
  248. extern SCM_CELLPTR scm_heap_org;
  249. extern SCM scm_freelist;
  250. extern long scm_gc_cells_collected;
  251. extern long scm_gc_malloc_collected;
  252. extern long scm_gc_ports_collected;
  253. extern long scm_cells_allocated;
  254. extern long scm_lcells_allocated;
  255. extern long scm_mallocated;
  256. extern long scm_lmallocated;
  257. extern long scm_mtrigger;
  258. extern SCM *scm_loc_loadpath;
  259.  
  260.  
  261. #ifdef __STDC__
  262. extern void scm_grew_lim (long nm);
  263. extern char * scm_must_malloc (long len, char *what);
  264. extern char * scm_must_realloc (char *where, long olen, long len, char *what);
  265. extern void scm_must_free (char *obj);
  266. extern void scm_permenant_object (SCM obj);
  267. extern SCM scm_alloc_large (int ncells, char * reason);
  268. extern void scm_gc_for_alloc (int ncells, SCM * freelistp);
  269. extern SCM scm_alloc_obj (SCM ncells, char * reason);
  270. extern void scm_init_io (void);
  271. extern SCM scm_markcdr (SCM ptr);
  272. extern SCM scm_mark0 (SCM ptr);
  273. extern sizet scm_free0 (SCM ptr);
  274. extern SCM scm_equal0 (SCM ptr1, SCM ptr2);
  275. extern void scm_init_storage (SCM_STACKITEM *stack_start_ptr, long init_heap_size, FILE * in, FILE * out, FILE * err);
  276. extern SCM * scm_mkarray (int size, int fillp);
  277. extern void scm_free_array (SCM * elts);
  278. extern void scm_mark_arrays (void);
  279. extern SCM scm_gc (void);
  280. extern void scm_remember (SCM * ptr);
  281. extern void scm_init_gc (void);
  282.  
  283. #else /* STDC */
  284. extern void scm_grew_lim ();
  285. extern char * scm_must_malloc ();
  286. extern char * scm_must_realloc ();
  287. extern void scm_must_free ();
  288. extern void scm_permenant_object ();
  289. extern SCM scm_alloc_large ();
  290. extern void scm_gc_for_alloc ();
  291. extern SCM scm_alloc_obj ();
  292. extern void scm_init_io ();
  293. extern SCM scm_markcdr ();
  294. extern SCM scm_mark0 ();
  295. extern sizet scm_free0 ();
  296. extern SCM scm_equal0 ();
  297. extern void scm_init_storage ();
  298. extern SCM * scm_mkarray ();
  299. extern void scm_free_array ();
  300. extern void scm_mark_arrays ();
  301. extern SCM scm_gc ();
  302. extern void scm_remember ();
  303. extern void scm_init_gc ();
  304.  
  305. #endif /* STDC */
  306.  
  307.  
  308. #include "marksweep.h"
  309. #endif  /* GCH */
  310.